package com.boby.homecamera.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log
import com.boby.homecamera.App
import com.boby.homecamera.constant.Constant
import com.boby.lib_common.BaseApplication
import java.io.File

 class ClientDBManager private constructor(context: Context, dbPath: String)
    : SQLiteOpenHelper(context, dbPath, null, DATABASE_VERSION) {
    private val TAG = "DBManager"
    companion object {
        private const val DATABASE_VERSION = 1
        val instance by lazy {
            val dbFileDir = BaseApplication.instance().filesDir
            if(!dbFileDir.exists()){
                dbFileDir.mkdirs()
            }
            val dbFile = File(dbFileDir, "client.db") //
            ClientDBManager(BaseApplication.instance(),"${dbFile.absoluteFile}")
        }

    }
     private var isInit = false
    @Synchronized
     fun init(){
        if(isInit){
            return
        }
        tb_camrea_device = CameraDeviceTable(writableDatabase)
        isInit = true
    }

     lateinit var tb_camrea_device:CameraDeviceTable
         private set



    override fun onCreate(db: SQLiteDatabase) {
        Log.d(TAG,"onCreate")
        CameraDeviceTable.createTable(db)
    }

    override fun onOpen(db: SQLiteDatabase) {
        super.onOpen(db)
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
        if (oldVersion < 2) {

        }
    }




}
